<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="node8.html" />
<link rel="prev" href="non-essential-built-in-funcs.html" />
<link rel="parent" href="builtin.html" />
<link rel="next" href="node8.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>2.3 Built-in Exceptions</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="2.2 non-essential Built-in Functions"
  href="non-essential-built-in-funcs.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="2. built-in Objects"
  href="builtin.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="2.4 built-in Constants"
  href="node8.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="non-essential-built-in-funcs.html">2.2 Non-essential Built-in Functions</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="builtin.html">2. Built-in Objects</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="node8.html">2.4 Built-in Constants</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h1><a name="SECTION004300000000000000000">
2.3 Built-in Exceptions</a>
</h1>

<p>
<a name="module-exceptions"></a>

<p>
Exceptions should be class objects.  
The exceptions are defined in the module <tt class="module">exceptions</tt>.  This
module never needs to be imported explicitly: the exceptions are
provided in the built-in namespace as well as the <tt class="module">exceptions</tt>
module.

<p>
<div class="note"><b class="label">Note:</b>
In past versions of Python string exceptions were supported.  In
Python 1.5 and newer versions, all standard exceptions have been
converted to class objects and users are encouraged to do the same.
String exceptions will raise a <code>DeprecationWarning</code> in Python 2.5 and
newer.
In future versions, support for string exceptions will be removed.

<p>
Two distinct string objects with the same value are considered different
exceptions.  This is done to force programmers to use exception names
rather than their string value when specifying exception handlers.
The string value of all built-in exceptions is their name, but this is
not a requirement for user-defined exceptions or exceptions defined by
library modules.
</div>

<p>
For class exceptions, in a <tt class="keyword">try</tt><a id='l2h-92' xml:id='l2h-92'></a> statement with
an <tt class="keyword">except</tt><a id='l2h-93' xml:id='l2h-93'></a> clause that mentions a particular
class, that clause also handles any exception classes derived from
that class (but not exception classes from which <em>it</em> is
derived).  Two exception classes that are not related via subclassing
are never equivalent, even if they have the same name.

<p>
The built-in exceptions listed below can be generated by the
interpreter or built-in functions.  Except where mentioned, they have
an ``associated value'' indicating the detailed cause of the error.
This may be a string or a tuple containing several items of
information (e.g., an error code and a string explaining the code).
The associated value is the second argument to the
<tt class="keyword">raise</tt><a id='l2h-94' xml:id='l2h-94'></a> statement.  For string exceptions, the
associated value itself will be stored in the variable named as the
second argument of the <tt class="keyword">except</tt> clause (if any).  For class
exceptions, that variable receives the exception instance.  If the
exception class is derived from the standard root class
<tt class="exception">BaseException</tt>, the associated value is present as the
exception instance's <tt class="member">args</tt> attribute.  If there is a single argument
(as is preferred), it is bound to the <tt class="member">message</tt> attribute.

<p>
User code can raise built-in exceptions.  This can be used to test an
exception handler or to report an error condition ``just like'' the
situation in which the interpreter raises the same exception; but
beware that there is nothing to prevent user code from raising an
inappropriate error.

<p>
The built-in exception classes can be sub-classed to define new
exceptions; programmers are encouraged to at least derive new
exceptions from the <tt class="exception">Exception</tt> class and not
<tt class="exception">BaseException</tt>.  More
information on defining exceptions is available in the
<em class="citetitle"><a
 href="../tut/tut.html"
 title="Python Tutorial"
 >Python Tutorial</a></em> under the heading
``User-defined Exceptions.''

<p>

<p>
The following exceptions are only used as base classes for other
exceptions.

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-95' xml:id='l2h-95' class="exception">BaseException</tt></b></dt>
<dd>
The base class for all built-in exceptions.  It is not meant to be directly
inherited by user-defined classes (for that use <tt class="exception">Exception</tt>).  If
<tt class="function">str()</tt> or <tt class="function">unicode()</tt> is called on an instance of this
class, the representation of the argument(s) to the instance are returned or
the emptry string when there were no arguments.  If only a single argument is
passed in, it is stored in the <tt class="member">message</tt> attribute.  If more than one
argument is passed in, <tt class="member">message</tt> is set to the empty string.  These
semantics are meant to reflect the fact that <tt class="member">message</tt> is to store a
text message explaining why the exception had been raised.  If more data needs
to be attached to the exception, attach it through arbitrary attributes on the
instance.  All arguments are also stored in <tt class="member">args</tt> as a tuple, but it will
eventually be deprecated and thus its use is discouraged.

<span class="versionnote">New in version 2.5.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-96' xml:id='l2h-96' class="exception">Exception</tt></b></dt>
<dd>
All built-in, non-system-exiting exceptions are derived
from this class.  All user-defined exceptions should also be derived
from this class.

<span class="versionnote">Changed in version 2.5:
Changed to inherit from <tt class="exception">BaseException</tt>.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-97' xml:id='l2h-97' class="exception">StandardError</tt></b></dt>
<dd>
The base class for all built-in exceptions except
<tt class="exception">StopIteration</tt>, <tt class="exception">GeneratorExit</tt>,
<tt class="exception">KeyboardInterrupt</tt> and <tt class="exception">SystemExit</tt>.
<tt class="exception">StandardError</tt> itself is derived from <tt class="exception">Exception</tt>.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-98' xml:id='l2h-98' class="exception">ArithmeticError</tt></b></dt>
<dd>
The base class for those built-in exceptions that are raised for
various arithmetic errors: <tt class="exception">OverflowError</tt>,
<tt class="exception">ZeroDivisionError</tt>, <tt class="exception">FloatingPointError</tt>.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-99' xml:id='l2h-99' class="exception">LookupError</tt></b></dt>
<dd>
The base class for the exceptions that are raised when a key or
index used on a mapping or sequence is invalid: <tt class="exception">IndexError</tt>,
<tt class="exception">KeyError</tt>.  This can be raised directly by
<tt class="function">sys.setdefaultencoding()</tt>.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-100' xml:id='l2h-100' class="exception">EnvironmentError</tt></b></dt>
<dd>
The base class for exceptions that
can occur outside the Python system: <tt class="exception">IOError</tt>,
<tt class="exception">OSError</tt>.  When exceptions of this type are created with a
2-tuple, the first item is available on the instance's <tt class="member">errno</tt>
attribute (it is assumed to be an error number), and the second item
is available on the <tt class="member">strerror</tt> attribute (it is usually the
associated error message).  The tuple itself is also available on the
<tt class="member">args</tt> attribute.

<span class="versionnote">New in version 1.5.2.</span>

<p>
When an <tt class="exception">EnvironmentError</tt> exception is instantiated with a
3-tuple, the first two items are available as above, while the third
item is available on the <tt class="member">filename</tt> attribute.  However, for
backwards compatibility, the <tt class="member">args</tt> attribute contains only a
2-tuple of the first two constructor arguments.

<p>
The <tt class="member">filename</tt> attribute is <code>None</code> when this exception is
created with other than 3 arguments.  The <tt class="member">errno</tt> and
<tt class="member">strerror</tt> attributes are also <code>None</code> when the instance was
created with other than 2 or 3 arguments.  In this last case,
<tt class="member">args</tt> contains the verbatim constructor arguments as a tuple.
</dd></dl>

<p>

<p>
The following exceptions are the exceptions that are actually raised.

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-101' xml:id='l2h-101' class="exception">AssertionError</tt></b></dt>
<dd>
<a id='l2h-102' xml:id='l2h-102'></a>Raised when an <tt class="keyword">assert</tt> statement fails.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-103' xml:id='l2h-103' class="exception">AttributeError</tt></b></dt>
<dd>
Raised when an attribute reference or assignment fails.  (When an
  object does not support attribute references or attribute assignments
  at all, <tt class="exception">TypeError</tt> is raised.)
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-104' xml:id='l2h-104' class="exception">EOFError</tt></b></dt>
<dd>
Raised when one of the built-in functions (<tt class="function">input()</tt> or
  <tt class="function">raw_input()</tt>) hits an end-of-file condition (EOF) without
  reading any data.
(N.B.: the <tt class="method">read()</tt> and <tt class="method">readline()</tt> methods of file
  objects return an empty string when they hit EOF.)
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-105' xml:id='l2h-105' class="exception">FloatingPointError</tt></b></dt>
<dd>
  Raised when a floating point operation fails.  This exception is
  always defined, but can only be raised when Python is configured
  with the <b class="programopt">--with-fpectl</b> option, or the
  <tt class="constant">WANT_SIGFPE_HANDLER</tt> symbol is defined in the
  <span class="file">pyconfig.h</span> file.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-106' xml:id='l2h-106' class="exception">GeneratorExit</tt></b></dt>
<dd>
  Raise when a generator's <tt class="method">close()</tt> method is called.
  It directly inherits from <tt class="exception">Exception</tt> instead of
  <tt class="exception">StandardError</tt> since it is technically not an error.
  
<span class="versionnote">New in version 2.5.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-107' xml:id='l2h-107' class="exception">IOError</tt></b></dt>
<dd>
Raised when an I/O operation (such as a <tt class="keyword">print</tt> statement,
  the built-in <tt class="function">open()</tt> function or a method of a file
  object) fails for an I/O-related reason, e.g., ``file not found'' or
  ``disk full''.

<p>
This class is derived from <tt class="exception">EnvironmentError</tt>.  See the
  discussion above for more information on exception instance
  attributes.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-108' xml:id='l2h-108' class="exception">ImportError</tt></b></dt>
<dd>
Raised when an <tt class="keyword">import</tt> statement fails to find the module
  definition or when a <code>from  ... import</code> fails to find a
  name that is to be imported.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-109' xml:id='l2h-109' class="exception">IndexError</tt></b></dt>
<dd>
Raised when a sequence subscript is out of range.  (Slice indices are
  silently truncated to fall in the allowed range; if an index is not a
  plain integer, <tt class="exception">TypeError</tt> is raised.)
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-110' xml:id='l2h-110' class="exception">KeyError</tt></b></dt>
<dd>
Raised when a mapping (dictionary) key is not found in the set of
  existing keys.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-111' xml:id='l2h-111' class="exception">KeyboardInterrupt</tt></b></dt>
<dd>
  Raised when the user hits the interrupt key (normally
  <kbd>Control-C</kbd> or <kbd>Delete</kbd>).  During execution, a check for
  interrupts is made regularly.
Interrupts typed when a built-in function <tt class="function">input()</tt> or
  <tt class="function">raw_input()</tt> is waiting for input also raise this
  exception.
  The exception inherits from <tt class="exception">BaseException</tt> so as to not be
  accidentally caught by code that catches <tt class="exception">Exception</tt> and thus
  prevent the interpreter from exiting.
  
<span class="versionnote">Changed in version 2.5:
Changed to inherit from <tt class="exception">BaseException</tt>.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-112' xml:id='l2h-112' class="exception">MemoryError</tt></b></dt>
<dd>
  Raised when an operation runs out of memory but the situation may
  still be rescued (by deleting some objects).  The associated value is
  a string indicating what kind of (internal) operation ran out of memory.
  Note that because of the underlying memory management architecture
  (C's <tt class="cfunction">malloc()</tt> function), the interpreter may not
  always be able to completely recover from this situation; it
  nevertheless raises an exception so that a stack traceback can be
  printed, in case a run-away program was the cause.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-113' xml:id='l2h-113' class="exception">NameError</tt></b></dt>
<dd>
  Raised when a local or global name is not found.  This applies only
  to unqualified names.  The associated value is an error message that
  includes the name that could not be found.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-114' xml:id='l2h-114' class="exception">NotImplementedError</tt></b></dt>
<dd>
  This exception is derived from <tt class="exception">RuntimeError</tt>.  In user
  defined base classes, abstract methods should raise this exception
  when they require derived classes to override the method.
  
<span class="versionnote">New in version 1.5.2.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-115' xml:id='l2h-115' class="exception">OSError</tt></b></dt>
<dd>
  This class is derived from <tt class="exception">EnvironmentError</tt> and is used
  primarily as the <tt class="module"><a href="module-os.html">os</a></tt> module's <code>os.error</code> exception.
  See <tt class="exception">EnvironmentError</tt> above for a description of the
  possible associated values.
  
<span class="versionnote">New in version 1.5.2.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-116' xml:id='l2h-116' class="exception">OverflowError</tt></b></dt>
<dd>
Raised when the result of an arithmetic operation is too large to be
  represented.  This cannot occur for long integers (which would rather
  raise <tt class="exception">MemoryError</tt> than give up).  Because of the lack of
  standardization of floating point exception handling in C, most
  floating point operations also aren't checked.  For plain integers,
  all operations that can overflow are checked except left shift, where
  typical applications prefer to drop bits than raise an exception.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-117' xml:id='l2h-117' class="exception">ReferenceError</tt></b></dt>
<dd>
  This exception is raised when a weak reference proxy, created by the
  <tt class="function"><tt class="module"><a href="module-weakref.html">weakref</a></tt>.proxy()</tt> function, is used to access
  an attribute of the referent after it has been garbage collected.
  For more information on weak references, see the <tt class="module"><a href="module-weakref.html">weakref</a></tt>
  module.
  
<span class="versionnote">New in version 2.2:
Previously known as the
                <tt class="exception"><tt class="module"><a href="module-weakref.html">weakref</a></tt>.ReferenceError</tt>
                exception.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-118' xml:id='l2h-118' class="exception">RuntimeError</tt></b></dt>
<dd>
  Raised when an error is detected that doesn't fall in any of the
  other categories.  The associated value is a string indicating what
  precisely went wrong.  (This exception is mostly a relic from a
  previous version of the interpreter; it is not used very much any
  more.)
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-119' xml:id='l2h-119' class="exception">StopIteration</tt></b></dt>
<dd>
  Raised by an iterator's <tt class="method">next()</tt> method to signal that there
  are no further values.
  This is derived from <tt class="exception">Exception</tt> rather than
  <tt class="exception">StandardError</tt>, since this is not considered an error in
  its normal application.
  
<span class="versionnote">New in version 2.2.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-120' xml:id='l2h-120' class="exception">SyntaxError</tt></b></dt>
<dd>
Raised when the parser encounters a syntax error.  This may occur in
  an <tt class="keyword">import</tt> statement, in an <tt class="keyword">exec</tt> statement, in a call
  to the built-in function <tt class="function">eval()</tt> or <tt class="function">input()</tt>, or
  when reading the initial script or standard input (also
  interactively).

<p>
Instances of this class have attributes <tt class="member">filename</tt>,
  <tt class="member">lineno</tt>, <tt class="member">offset</tt> and <tt class="member">text</tt> for easier access
  to the details.  <tt class="function">str()</tt> of the exception instance returns
  only the message.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-121' xml:id='l2h-121' class="exception">SystemError</tt></b></dt>
<dd>
  Raised when the interpreter finds an internal error, but the
  situation does not look so serious to cause it to abandon all hope.
  The associated value is a string indicating what went wrong (in
  low-level terms).

<p>
You should report this to the author or maintainer of your Python
  interpreter.  Be sure to report the version of the Python
  interpreter (<code>sys.version</code>; it is also printed at the start of an
  interactive Python session), the exact error message (the exception's
  associated value) and if possible the source of the program that
  triggered the error.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-122' xml:id='l2h-122' class="exception">SystemExit</tt></b></dt>
<dd>
This exception is raised by the <tt class="function">sys.exit()</tt> function.  When it
  is not handled, the Python interpreter exits; no stack traceback is
  printed.  If the associated value is a plain integer, it specifies the
  system exit status (passed to C's <tt class="cfunction">exit()</tt> function); if it is
  <code>None</code>, the exit status is zero; if it has another type (such as
  a string), the object's value is printed and the exit status is one.

<p>
Instances have an attribute <tt class="member">code</tt> which is set to the
  proposed exit status or error message (defaulting to <code>None</code>).
  Also, this exception derives directly from <tt class="exception">BaseException</tt> and
  not <tt class="exception">StandardError</tt>, since it is not technically an error.

<p>
A call to <tt class="function">sys.exit()</tt> is translated into an exception so that
  clean-up handlers (<tt class="keyword">finally</tt> clauses of <tt class="keyword">try</tt> statements)
  can be executed, and so that a debugger can execute a script without
  running the risk of losing control.  The <tt class="function">os._exit()</tt> function
  can be used if it is absolutely positively necessary to exit
  immediately (for example, in the child process after a call to
  <tt class="function">fork()</tt>).

<p>
The exception inherits from <tt class="exception">BaseException</tt> instead of
  <tt class="exception">StandardError</tt> or <tt class="exception">Exception</tt> so that it is not
  accidentally caught by code that catches <tt class="exception">Exception</tt>.  This allows
  the exception to properly propagate up and cause the interpreter to exit.
  
<span class="versionnote">Changed in version 2.5:
Changed to inherit from <tt class="exception">BaseException</tt>.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-123' xml:id='l2h-123' class="exception">TypeError</tt></b></dt>
<dd>
  Raised when an operation or function is applied to an object
  of inappropriate type.  The associated value is a string giving
  details about the type mismatch.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-124' xml:id='l2h-124' class="exception">UnboundLocalError</tt></b></dt>
<dd>
  Raised when a reference is made to a local variable in a function or
  method, but no value has been bound to that variable.  This is a
  subclass of <tt class="exception">NameError</tt>.

<span class="versionnote">New in version 2.0.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-125' xml:id='l2h-125' class="exception">UnicodeError</tt></b></dt>
<dd>
  Raised when a Unicode-related encoding or decoding error occurs.  It
  is a subclass of <tt class="exception">ValueError</tt>.

<span class="versionnote">New in version 2.0.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-126' xml:id='l2h-126' class="exception">UnicodeEncodeError</tt></b></dt>
<dd>
  Raised when a Unicode-related error occurs during encoding.  It
  is a subclass of <tt class="exception">UnicodeError</tt>.

<span class="versionnote">New in version 2.3.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-127' xml:id='l2h-127' class="exception">UnicodeDecodeError</tt></b></dt>
<dd>
  Raised when a Unicode-related error occurs during decoding.  It
  is a subclass of <tt class="exception">UnicodeError</tt>.

<span class="versionnote">New in version 2.3.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-128' xml:id='l2h-128' class="exception">UnicodeTranslateError</tt></b></dt>
<dd>
  Raised when a Unicode-related error occurs during translating.  It
  is a subclass of <tt class="exception">UnicodeError</tt>.

<span class="versionnote">New in version 2.3.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-129' xml:id='l2h-129' class="exception">ValueError</tt></b></dt>
<dd>
  Raised when a built-in operation or function receives an argument
  that has the right type but an inappropriate value, and the
  situation is not described by a more precise exception such as
  <tt class="exception">IndexError</tt>.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-130' xml:id='l2h-130' class="exception">WindowsError</tt></b></dt>
<dd>
  Raised when a Windows-specific error occurs or when the error number
  does not correspond to an <tt class="cdata">errno</tt> value.  The
  <tt class="member">winerror</tt> and <tt class="member">strerror</tt> values are created from the
  return values of the <tt class="cfunction">GetLastError()</tt> and
  <tt class="cfunction">FormatMessage()</tt> functions from the Windows Platform API.
  The <tt class="member">errno</tt> value maps the <tt class="member">winerror</tt> value to 
  corresponding <code>errno.h</code> values.
  This is a subclass of <tt class="exception">OSError</tt>.

<span class="versionnote">New in version 2.0.</span>

<span class="versionnote">Changed in version 2.5:
Previous versions put the <tt class="cfunction">GetLastError()</tt>
codes into <tt class="member">errno</tt>.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-131' xml:id='l2h-131' class="exception">ZeroDivisionError</tt></b></dt>
<dd>
  Raised when the second argument of a division or modulo operation is
  zero.  The associated value is a string indicating the type of the
  operands and the operation.
</dd></dl>

<p>

<p>
The following exceptions are used as warning categories; see the
<tt class="module"><a href="module-warnings.html">warnings</a></tt> module for more information.

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-132' xml:id='l2h-132' class="exception">Warning</tt></b></dt>
<dd>
Base class for warning categories.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-133' xml:id='l2h-133' class="exception">UserWarning</tt></b></dt>
<dd>
Base class for warnings generated by user code.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-134' xml:id='l2h-134' class="exception">DeprecationWarning</tt></b></dt>
<dd>
Base class for warnings about deprecated features.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-135' xml:id='l2h-135' class="exception">PendingDeprecationWarning</tt></b></dt>
<dd>
Base class for warnings about features which will be deprecated in the future.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-136' xml:id='l2h-136' class="exception">SyntaxWarning</tt></b></dt>
<dd>
Base class for warnings about dubious syntax
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-137' xml:id='l2h-137' class="exception">RuntimeWarning</tt></b></dt>
<dd>
Base class for warnings about dubious runtime behavior.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-138' xml:id='l2h-138' class="exception">FutureWarning</tt></b></dt>
<dd>
Base class for warnings about constructs that will change semantically
in the future.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-139' xml:id='l2h-139' class="exception">ImportWarning</tt></b></dt>
<dd>
Base class for warnings about probable mistakes in module imports.

<span class="versionnote">New in version 2.5.</span>

</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-140' xml:id='l2h-140' class="exception">UnicodeWarning</tt></b></dt>
<dd>
Base class for warnings related to Unicode.

<span class="versionnote">New in version 2.5.</span>

</dd></dl>

<p>
The class hierarchy for built-in exceptions is:

<p>
<div class="verbatim">
<pre>BaseException
 +-- SystemExit
 +-- KeyboardInterrupt
 +-- Exception
      +-- GeneratorExit
      +-- StopIteration
      +-- StandardError
      |    +-- ArithmeticError
      |    |    +-- FloatingPointError
      |    |    +-- OverflowError
      |    |    +-- ZeroDivisionError
      |    +-- AssertionError
      |    +-- AttributeError
      |    +-- EnvironmentError
      |    |    +-- IOError
      |    |    +-- OSError
      |    |         +-- WindowsError (Windows)
      |    |         +-- VMSError (VMS)
      |    +-- EOFError
      |    +-- ImportError
      |    +-- LookupError
      |    |    +-- IndexError
      |    |    +-- KeyError
      |    +-- MemoryError
      |    +-- NameError
      |    |    +-- UnboundLocalError
      |    +-- ReferenceError
      |    +-- RuntimeError
      |    |    +-- NotImplementedError
      |    +-- SyntaxError
      |    |    +-- IndentationError
      |    |         +-- TabError
      |    +-- SystemError
      |    +-- TypeError
      |    +-- ValueError
      |    |    +-- UnicodeError
      |    |         +-- UnicodeDecodeError
      |    |         +-- UnicodeEncodeError
      |    |         +-- UnicodeTranslateError
      +-- Warning
           +-- DeprecationWarning
           +-- PendingDeprecationWarning
           +-- RuntimeWarning
           +-- SyntaxWarning
           +-- UserWarning
           +-- FutureWarning
	   +-- ImportWarning
	   +-- UnicodeWarning
</pre>
<div class="footer">
<a href="exception_hierarchy.txt" type="text/plain">Download as text (original file name: <span class="file">../../Lib/test/exception_hierarchy.txt</span>).</a>
</div></div>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="2.2 non-essential Built-in Functions"
  href="non-essential-built-in-funcs.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="2. built-in Objects"
  href="builtin.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="2.4 built-in Constants"
  href="node8.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="non-essential-built-in-funcs.html">2.2 Non-essential Built-in Functions</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="builtin.html">2. Built-in Objects</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="node8.html">2.4 Built-in Constants</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
